/**
 * 区域管理 api js
 */
import request from "@/utils/request";

const baseURL = process.env.VUE_APP_BASE_API;

/**
 *
 * @param {*} data
 * 保存区域数据
 */
export function saveOrUpdate(data) {
  return request({
    url:
      process.env.VUE_APP_KSTB_ROUTE_PATH + "/yxpz/regionManage/saveOrUpdate",
    method: "post",
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
    data: data
  });
}

/**
 * 分页查询列表数据
 * @param {*} params
 */
export function queryPages(params) {
  return request({
    url: process.env.VUE_APP_KSTB_ROUTE_PATH + "/yxpz/regionManage/queryPages",
    method: "get",
    params: params
  });
}

/**
 * 更新区域状态
 * @param {*} id
 * @param {*} stateFlag
 */
export function updateStateFlag(id, stateFlag) {
  return request({
    url:
      process.env.VUE_APP_KSTB_ROUTE_PATH +
      "/yxpz/regionManage/updateStateFlag",
    method: "get",
    params: {
      id,
      stateFlag
    }
  });
}

/**
 * 通过主键获取对象数据
 * @param {*} id
 */
export function getById(id) {
  return request({
    url: process.env.VUE_APP_KSTB_ROUTE_PATH + "/yxpz/regionManage/getById",
    method: "get",
    params: {
      id
    }
  });
}

/**
 * 通过主键删除区域数据
 * @param {*} id
 */
export function deleteRegionManageById(id) {
  return request({
    url:
      process.env.VUE_APP_KSTB_ROUTE_PATH +
      "/yxpz/regionManage/deleteRegionManageById",
    method: "get",
    params: {
      id
    }
  });
}

/**
 * 通过code查询是否存在区域对象数据
 * @param {*} code
 */
export function existRegionManageByCode(code) {
  return request({
    url:
      process.env.VUE_APP_KSTB_ROUTE_PATH +
      `/yxpz/regionManage/existRegionManageByCode/${code}`,
    method: "post"
  });
}

/**
 * 根据条件查询区域数据，并且里面结构化了市级数据
 */
export function queryListAndChild(data = {}) {
  return request({
    url:
      process.env.VUE_APP_KSTB_ROUTE_PATH +
      "/yxpz/regionManage/queryListAndChild",
    method: "post",
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    },
    data: data
  });
}

/**
 * 查询基础服务中 所有区划数据
 */
export function queryAllDistrict() {
  return request({
    url: `/platform/security/common/queryAllDistrictSimpleTree`,
    method: "get"
  });
}

/**
 * 根据childRegionOid查询子区划的对象数据
 * @param {*} childRegionOid
 * @returns
 */
export function queryByChildRegionOid(childRegionOid) {
  return request({
    url:
      process.env.VUE_APP_KSTB_ROUTE_PATH +
      `/yxpz/regionManage/queryByChildRegionOid/${childRegionOid}`,
    method: "post",
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    }
  });
}

/**
 * 根据citycode查询包含的区县数据
 * @param {*} cityCode
 * @returns
 */
export function queryCountyCodesDataByCityCode(cityCode = "") {
  return request({
    url:
      process.env.VUE_APP_KSTB_ROUTE_PATH +
      `/yxpz/regionManage/queryCountyCodesDataByCityCode/${cityCode}`,
    method: "post",
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    }
  });
}
